import 'dart:async';

import 'package:geolocator/geolocator.dart';

import 'DioUtils.dart';

class JPushUtils{
  static Timer timer;
  static void beginTimer(String uid){
    if(timer != null){
      timer.cancel();
      timer = null;
    }
    Timer.periodic(Duration(minutes: 1), (t) {
      //到时回调
      print('afterTimer=' + DateTime.now().toString());
      timer = t;
      Geolocator()
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
          .then((position) {
        DioUtils.updateNewAddress(uid,
            lat: position.latitude.toString(),
            lng: position.longitude.toString())
            .then((result) {
          print("更新地址：${result.code}");
        });
      });
    });
  }

  static void closeTimer(){
    timer.cancel();
    timer = null;
  }
}